package com.tb.exception;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * comment
 *
 * @author zhao yuan
 * @since 2018/9/14
 */
public class ExceptionTest {

    private Logger logger = LoggerFactory.getLogger(ExceptionTest.class);

    @Test
    public void testExceptionMessage(){
        try {
            propagateExceptionAttachMsg();
        } catch (OneException e) {
            logger.error(e.getMessage());  // out: one error.
        }

        try {
            propagateException();
        } catch (OneException e) {
            logger.error(e.getMessage());  // out: java.lang.Exception: chu yi chang le.
        }

    }

    private void propagateException() throws OneException {
        try {
            makeException();
        } catch (Exception e) {
            throw new OneException(e);
        }
    }

    private void propagateExceptionAttachMsg() throws OneException {
        try {
            makeException();
        } catch (Exception e) {
            throw new OneException("one error.",e);
        }
    }

    private void makeException() throws Exception {
        throw new Exception("chu yi chang le.");
    }
}
